import { defineStore } from "pinia";
import defaultSongUrl from "../assets/music/FairyTaleTown.mp3"
import handsome from "../assets/handsome.jpg"

const useSongURLStore = defineStore('songURL', {
    state: () => {
        return {
            songID:JSON.parse(localStorage.getItem('songInfomation') as string)?.id ?? 0,
            songURL: JSON.parse(localStorage.getItem('songInfomation') as string)?.songUrl ?? defaultSongUrl,
            songName: JSON.parse(localStorage.getItem('songInfomation') as string)?.songName ?? "童话镇",
            singer: JSON.parse(localStorage.getItem('songInfomation') as string)?.singer ?? "陈一发",
            picture: JSON.parse(localStorage.getItem('songInfomation') as string)?.picUrl ?? handsome,
            durations: JSON.parse(localStorage.getItem('songInfomation') as string)?.duration ?? 234234,
            playList: JSON.parse(localStorage.getItem('playList') as any) ?? [],
            playIndex: JSON.parse(localStorage.getItem('songInfomation') as string)?.index ?? 0,
            playStates: JSON.parse(localStorage.getItem("playState") as string) ?? true,
        }
    },
    actions: {
        init(url: string, name: string, singer: string, picUrl: string, duration: number, index: number, id: number) {
            this.songID = id
            this.songURL = url
            this.songName = name
            this.singer = singer
            this.picture = picUrl
            this.durations = duration
            this.playIndex = index
        },
        // 存储当前播放列表
        initPlayList(playList: any) {
            this.playList = playList
        },
        // 随机播放函数
        randomPlayNum(index: number) {
            this.playIndex = index
        },
        // 播放/暂停状态
        playStateChange(value: boolean) {
            this.playStates = value
        }
    }
})


export default useSongURLStore
